package com.lock.type;

import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.ReentrantLock;

/**
 * @Author: tgy
 * @Date: 2020-11-14 16:07
 */

class Student {

    private boolean meal;

    private java.util.concurrent.locks.ReentrantLock lock = new ReentrantLock();

    private Condition condition = lock.newCondition();


    public void eat(){

        while (true){

            lock.lock();

            try {

                while (!meal) {

                    condition.await();
                }

                System.out.println("eat");

            } catch (InterruptedException e) {

            } finally {
                lock.unlock();
            }
        }

    }



}


public class ReentrantLockDemo01 {

    public static void main(String[] args) {




    }
}
